package stu.info.student.info.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import stu.info.student.info.entity.Room;
import stu.info.student.info.entity.Student;
import stu.info.student.info.mapper.roomMapper;
import stu.info.student.info.mapper.studentMapper;

import java.util.List;

@Slf4j
@Api(tags ="房间管理模块")
@RestController
@RequestMapping("/room")
public class roomController {
    @Autowired
    private roomMapper roomMapper;

    @ApiOperation("添加房间")
    @PostMapping("/add")
    int addRoom(@RequestBody Room room)
    {
        roomMapper.insert(room);
        log.debug("添加房间成功>>>{}",room);
        return 200;
    }

    @ApiOperation("删除房间")
    @PostMapping("/delete")
    int deleteRoom(Long rno)
    {
        roomMapper.deleteById(rno);
        log.debug("删除房间id为{}成功>>>",rno);
        return 200;
    }

    @ApiOperation("查询房间")
    @PostMapping("/select")
    List<Room> getRoom()
    {
        return roomMapper.select();
    }

    @ApiOperation("修改房间当前人数信息")
    @PostMapping("/update")
    int updateRoom(@RequestBody Room room)
    {
        if(room.getNow()<=room.getSize()) {
            roomMapper.updateById(room);
            log.debug("修改房间id为{}成功...>>>", room.getRno());
            return 200;
        }
        else{
            log.debug("修改失败，房间人数已满...");
            return 201;
        }
    }
}
